package com.bilibili.juc.AtomicTest;

import java.util.concurrent.TimeUnit;

/**
 * @author 小泽
 * @create 2022-09-23  9:39
 * 记得每天敲代码哦
 */
//方法一（不推荐，做做Demo还行）
public class AtomicIntegerDemo1 {
       public static final int SIZE = 50;
       public static void main(String[] args) {
              MyNumber myNumber = new MyNumber();
              for(int i = 1;i <= SIZE;i ++){
                     new Thread(() -> {
                            for(int j = 1;j <= 1000;j ++){
                                   myNumber.addPlusPlus();
                            }
                     },String.valueOf(i)).start();
              }
              try {
                     TimeUnit.SECONDS.sleep(2);
              } catch (InterruptedException e) {
                     e.printStackTrace();
              }
              System.out.println(Thread.currentThread().getName()+"\t"+"result: "+myNumber.atomicInteger);
       }
}
